package com.zhou.project.modules.circle.circleType.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.project.components.base.service.BaseService;
import com.zhou.project.modules.circle.circleType.dao.CircleTypeDao;
import com.zhou.project.modules.circle.circleType.entity.CircleType;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@CacheConfig(cacheNames = "type")
public class CircleTypeService extends BaseService<CircleTypeDao, CircleType> {



    @Cacheable(key = "'page:'+#entity.current+':'+#entity.size+':'+#entity.createdBy")
    public Page<CircleType> page(CircleType entity)
    {
        entity.setId(currentAuthentication.getCurrentUserId());
        //分页对象
        Page<CircleType> page=Page.of(entity.getCurrent(),entity.getSize());

        //按分页查询
        QueryWrapper<CircleType> wrapper =new QueryWrapper<>();
        if (StringUtils.hasLength(entity.getName()))
        {
            wrapper.like("name",entity.getName());
        }

        int userId=currentAuthentication.getCurrentUserId();

        wrapper.eq("created_by",userId);

        return baseMapper.selectPage(page,wrapper);
    }



}
